package com.gemme.gemme.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.Button;
import android.widget.RelativeLayout;

import com.gemme.gemme.R;
import com.gemme.gemme.test.MyPhotoFragment;
import com.luck.picture.lib.config.PictureConfig;
import com.luck.picture.lib.entity.LocalMedia;

import java.util.List;

import androidx.appcompat.app.AppCompatActivity;

public class GMPhotoView extends RelativeLayout {
    private Context context;
    Button button1;
    private int maxSelectNum = 9;

    public GMPhotoView(Context context) {
        this(context,null);
    }

    public GMPhotoView(Context context, AttributeSet attrs) {
        this(context, attrs,0);
    }

    public GMPhotoView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        this.context = context;
        initView();
    }

    private void initView() {
        LayoutInflater.from(context).inflate(R.layout.phone_view,this);
    }

    MyPhotoFragment fragment;
//    全部.PictureMimeType.ofAll()、图片.ofImage()、视频.ofVideo()、音频.ofAudio()
    public void setChooseMode(int chooseMode){
        if(!(context instanceof AppCompatActivity))
            return;

        AppCompatActivity act = (AppCompatActivity) this.context;

        fragment = new MyPhotoFragment();

        act.getSupportFragmentManager().beginTransaction().add(R.id.tab_content, fragment,
                PictureConfig.EXTRA_FC_TAG).show(fragment)
                .commit();
        fragment.setChooseMode(chooseMode);
        fragment.setMaxSelectNum(maxSelectNum);
    }

    public void setClickToPicture() {
        fragment.setClickToPicture();
    }


    public void setMaxSelectNum(int maxSelectNum){
        this.maxSelectNum = maxSelectNum;
    }

    public List<LocalMedia> getData(){
        return fragment.getData();
    }
}
